<template>
	<view style="text-align: center;padding: 30rpx;">
		<view class="imgs">
			<image src="../../static/images/logo.jpg" mode="aspectFit" style="width: 180rpx;height: 180rpx;"></image>
			<view style="margin-top: 30rpx;color: #7A7E83;font-size: 34rpx;">
				<text>登录后可继续当前操作</text>
			</view>
			<view style="margin-top: 150rpx;">
				<u-button hover-class="none" type="primary" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" shape="square" :custom-style="{color:'#FFFFFF',backgroundColor: '#07C160'}">微信手机号一键登录</u-button>
			</view>

		</view>
		<view style="margin-top: 500rpx;color: #7A7E83;">
			<text>系统将为您自动注册，注册或登陆即代表您同意我们的</text>
			<text style="color: #2B85E4;" @click="goyszc">《服务协议》</text>
			与
			<text style="color: #2B85E4;" @click="goyszc">《隐私政策》</text>
			
		</view>
		<u-toast ref="uToast" :icon="false" />
	</view>
</template>

<script>
	import Config from '../../common/config.js';
	export default {
		data() {
			return {
				code: "",
				path: ""
			}
		},
		onLoad(pamar) {
			let path = decodeURIComponent(pamar.path)
			this.path = path
			this.login()
		},
		methods: {
			goyszc(){
				uni.navigateTo({
					url:"../yszc/yszc"
				})
			},
			login() {
				let that = this;
				wx.login({
					success(res) {
						that.code = res.code
					}

				})
			},
			getPhoneNumber(e) {
				let that = this;
				if (e.detail.encryptedData != undefined) {
					uni.request({
						url: Config.ServerIP + "/uaa/auth/login",
						method: "POST",
						data: {
							code: that.code,
							encryptedData: e.detail.encryptedData,
							iv: e.detail.iv,
							productCode: 'LIKE'
						},
						success: (data) => {

							if (data.data.code === 200) {
								Config.token = data.data.data.access_token;
								Config.openid = data.data.data.userInfo.openId;
								Config.phone = data.data.data.userInfo.sysUser.phoneNumber;
								uni.setStorageSync("token", Config.token)
								uni.setStorageSync("phone", Config.phone)
								uni.setStorageSync("openid", Config.openid)
								if (that.path != "") {
									if(that.path.indexOf("my/my") !=-1){
										uni.reLaunch({
											url: that.path
										});
									}else{
										uni.redirectTo({
											url: that.path
										})
									}
									
								} else {
									uni.navigateBack({
										delta: 1
									});
								}

							} else {
								uni.showToast({
									icon:"none",
								    title: '授权失败请重试',
								    duration: 1000
								});
								// that.$refs.uToast.show({
								// 	title: '授权失败，请重新授权！',
								// 	type: 'error'
								// })
							}
						}
					})
				} else {
					uni.showToast({
						icon:"none",
					    title: '用户拒绝授权！',
					    duration: 1000
					});
					// that.$refs.uToast.show({
					// 	title: '用户拒绝手机号授权，请重新授权！',
					// 	type: 'error'
					// })
					// if (that.path != "") {
					// 	uni.reLaunch({
					// 		url: that.path
					// 	});
					// } else {
					// 	uni.navigateBack({
					// 		delta: 1
					// 	});
					// }
				}




			},

		},
	}
</script>

<style>
	.footer {
		color: #fff;
		line-height: 100rpx;
		flex: 0 0 100rpx;
		/* 不放大不缩小固定100rpx */
	}

	.imgs {
		width: 100%;
		margin-top: 160rpx;
	}
</style>
